<?php
/**
 * Created by PhpStorm.
 * User: 冰封~零度
 * Date: 2018/10/15
 * Time: 15:20
 */

namespace app\mobile\controller;


use think\Controller;
use think\Db;
use think\Session;

class Problem extends Controller
{
    // 提问页面
    public function index()
    {
        // 获取当前用户信息
        $userSession = Session::get('puser');
        // 查询问题分类
        $problemCate = Db::table('zz_cate')->where('zz_cate_status',1)->select();

        return view('problem/problem',[
            'userSession' => $userSession,
            'problemCate' => $problemCate
        ]);
    }

    // 提问提交处理
    public function dosub()
    {
        // 判断用户是否登录
        $userSession = Session::get('puser');
        if (empty($userSession)){
            $res['status'] = 2;
            return json($res);
        } else {
            // 接收数据
            $cid = input('cid');
            $tit = input('title');
            $content = input('desc');
            $uid = input('userid');
            $data = [];
            $data['zz_problem_cid'] = $cid;
            $data['zz_problem_tit'] = $tit;
            $data['zz_uid'] = $uid;
            $data['zz_problem_content'] = $content;
            $data['zz_problem_time'] = date('Y-m-d');
            // 添加到数据库
            Db::table('zz_problem')->insert($data);
            $res['status'] = 1;
            return json($res);
        }
    }






}